import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';

/// created by devin
/// 2024/12/26 10:21
/// description: 
class DialogUtil {

  static Future<bool?> showCustomConfirmDialog(BuildContext context, {
    String? title,
    String? content,
    String? positiveText,
    Function? onConfirm,
    Color? positiveColor,
    Color? positiveTextColor,
    String? negativeText,
    Function? onCancel,
    Color? negativeColor,
    Color? negativeTextColor,
    bool showCancel = true,
    bool cancelable = false,
  }) async {
    return await showDialog(context: context, builder: (context) =>
        PopScope(
          canPop: cancelable,
          child: AlertDialog(
            insetPadding: EdgeInsets.symmetric(horizontal: 28.w),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8.w),
            ),
            content: Container(
              padding: EdgeInsets.fromLTRB(0.w, 10.h, 0.w, 0.h),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Visibility(
                    visible: title != null,
                    child: Padding(
                      padding: EdgeInsets.only(bottom: 10.h),
                      child: Text(title ?? '', style: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: FontWeight.w600,
                      ),),
                    ),
                  ),
                  Text(content ?? '', style: TextStyle(
                    fontWeight: FontWeight.w400,
                  ),),
                  SizedBox(height: 32.h,),
                  Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Visibility(
                        visible: showCancel,
                        child: Container(
                          margin: EdgeInsets.only(right: 12.w),
                          child: GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop(false);
                              if (onCancel != null) onCancel();
                            },
                            child: Text(negativeText ?? '取消', style: TextStyle(
                              color: negativeTextColor ?? Colors.black,
                              fontWeight: FontWeight.bold,
                            ),),
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: () {
                          Navigator.of(context).pop(true);
                          if (onConfirm != null) onConfirm();
                        },
                        child: Text(positiveText ?? '确定', style: TextStyle(
                          color: positiveTextColor ?? Colors.black,
                          fontWeight: FontWeight.bold,
                        ),),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      barrierDismissible: cancelable,
    );
  }
}

